<template>
  <div>
    <router-view />
    <!-- <router-view v-slot="{ Component }">
      <transition>
        <keep-alive>
          <component :is="Component" />
        </keep-alive>
      </transition>
    </router-view> -->
    <!--底部导航栏-->
    <nav>
      <!--首页-->
      <router-link to="/home" class="tab-bar-item">
        <div class="icon"><i class="iconfont icon-shouye-shouye"></i></div>
        <div>首页</div>
      </router-link>
      <!--分类-->
      <router-link to="/category" class="tab-bar-item">
        <div class="icon"><i class="iconfont icon-fenlei"></i></div>
        <div>分类</div>
      </router-link>
      <!--购物车-->
      <router-link to="/shopcart" class="tab-bar-item">
        <div class="icon">
          <van-badge :content="$store.state.cartCount" max="9">
            <div class="child" />
            <i class="iconfont icon-gouwuche"></i>
          </van-badge>
        </div>
        <div>购物车</div>
      </router-link>
      <!--个人中心-->
      <router-link to="/proilte" class="tab-bar-item">
        <div class="icon"><i class="iconfont icon-gerenzhongxin"></i></div>
        <div>个人中心</div>
      </router-link>
    </nav>
  </div>
</template>
<script>
import { onMounted } from "vue";
import { useStore } from "vuex";
export default {
  setup() {
    const store = useStore();
    onMounted(()=>{
      store.dispatch('updateCart');
    })
  },
};
</script>

<style lang="scss">
@import "assets/css/base.css";
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

nav {
  background: #f6f6f6;
  display: flex;
  position: fixed;
  left: 0px;
  right: 0px;
  bottom: 0px;
  box-shadow: 0 -3px 1px rgba(100, 100, 100, 0.2);
  a {
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}

.tab-bar-item {
  flex: 1;
  text-align: center;
  font-size: var(--font-size);
  height: 50px;
}

.tab-bar-item .icon {
  width: 24px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
  margin-bottom: 3px;
}
</style>
